<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//输入：nums = [2,0,2,1,1,0]
			//输出：[0,0,1,1,2,2]
			/**
			 * @param {number[]} nums
			 * @return {void} Do not return anything, modify nums in-place instead.
			 */
			const sortColors = nums => {
			    const swap = (i, j) => ([nums[i], nums[j]] = [nums[j], nums[i]]);
			    let [start, end] = [0, nums.length - 1];
			    for (let i = 0; i <= end; i++) {
			        while (i <= end && nums[i] == 2){
						swap(i, end--);
					} 
			        if (nums[i] === 0){
						swap(i, start++);
					} 
			    }
				return nums;
			};
			// console.log(sortColors([2, 0, 2, 1, 1, 0]));
			// console.log(sortColors([2,0,1]));
			console.log(sortColors([2, 0, 2, 1, 1, 0]));
		</script>
	</body>
</html>
